<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>10.10 课后作业</title>
    <style>
        div {
            padding: 10px;
            margin: 5px;
            border: 1px solid #ccc;
        }

        .active {
            background: #ffecb3;
            border-color: #ffc107;
        }
    </style>
</head>

<body>
    <h3>DOM操作</h3>

    <div id="one">第一个div（ID: one）</div>
    <div class="test">第二个div（class: test）</div>
    <div class="test">第三个div（class: test）</div>
    <ul>
        <li>列表项1</li>
        <li>列表项2</li>
    </ul>

    <script>
        let firstDiv = document.getElementById("one");
        firstDiv.textContent = "我被修改啦！";
        firstDiv.style.color = "blue";

        let testDivs = document.getElementsByClassName("test");
        testDivs[0].style.border = "2px solid green";

        let listItems = document.getElementsByTagName("li");
        listItems[1].style.backgroundColor = "lightpink";

        let newP = document.createElement("p");
        newP.textContent = "这是新创建的段落";
        newP.className = "active";
        document.body.appendChild(newP);

        let allDivs = document.querySelectorAll("div");
        allDivs.forEach(div => {
            div.style.marginTop = "8px";
        });
    </script>
</body>

</html>